﻿using NUnit.Framework;
using Validate.Extensions;

namespace Validate.UnitTests
{
    [TestFixture]
    public class ValidatorTests_LesserThan
    {
        [Test]
        public void ShouldPassForLesserThan()
        {
            Assert.IsTrue(5.Validate().IsLesserThan(i => i, 10, "Failed").IsValid);
        }

        [Test]
        public void ShouldFailForLesserThan()
        {
            Assert.IsFalse(5.Validate().IsLesserThan(i => i, 5, "Failed").IsValid);
            Assert.IsFalse(5.Validate().IsLesserThan(i => i, 0, "Failed").IsValid);
        }
        
        [Test]
        public void ShouldBeAbleToVerifyAutoGeneratedValidationMessage1()
        {
            var person = new Person { Name = "Some Name", Age = 18, Goals = 100 };
            var validator = person.Validate(new ValidationOptions { StopOnFirstError = false })
                .IsLesserThan(v => v.Age, 18)
                .IsLesserThan(v => v.Goals, 50);
            Assert.That(validator.Errors[0].Message, Is.EqualTo("Person.Age should be lesser than 18."));
            Assert.That(validator.Errors[1].Message, Is.EqualTo("Person.Goals should be lesser than 50."));
        }

        [Test]
        public void ShouldPassForLesserThanOtherMember()
        {
            var person = new Person { Name = "Some Name", Age = 12, Goals = 10 };
            var validator = person.Validate()
                            .IsLesserThan(p => p.Goals, p => p.Age, "Goals scored should be lesser than age.");
            Assert.IsTrue(validator.IsValid);
        }

        [Test]
        public void ShouldFailForLesserThanOtherMember()
        {
            var person = new Person { Name = "Some Name", Age = 12, Goals = 20 };
            var validator = person.Validate()
                            .IsLesserThan(p => p.Goals, p => p.Age, "Goals scored should be lesser than age.");
            Assert.IsFalse(validator.IsValid);
            Assert.AreEqual(validator.Errors[0].Message, "Goals scored should be lesser than age.");
        }

        [Test]
        public void ShouldBeAbleToVerifyAutoGeneratedValidationMessage2()
        {
            var person = new Person { Name = "Some Name", Age = 12, Goals = 20 };
            var validator = person.Validate()
                            .IsLesserThan(p => p.Goals, p => p.Age);
            Assert.IsFalse(validator.IsValid);
            Assert.AreEqual(validator.Errors[0].Message, "Person.Goals should be lesser than Person.Age.");
        }
    }
}